package com.lhd.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lhd.mapper.GoodMapper;
import com.lhd.pojo.Good;
import com.lhd.pojo.PageBean;
import com.lhd.pojo.PageCondition;
import com.lhd.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodServiceImpl implements GoodService {
    @Autowired
    GoodMapper goodMapper;
    @Override
    public List<Good> getAll() {
        return goodMapper.getAll();
    }

    @Override
    public void getById(Integer id) {
        goodMapper.getById(id);
    }

    @Override
    public PageBean<Good> getWithCondition(Good good, PageCondition pageCondition) {
        PageHelper.startPage(pageCondition.getPageNum(),pageCondition.getPageSize());
        Page<Good> page = goodMapper.getWithCondition(good);
        long total = page.getTotal();
        List<Good> result = page.getResult();
        return new PageBean<>(total,result);
    }

    @Override
    public void update(Good good) {
        goodMapper.update(good);
    }

    @Override
    public void add(Good good) {
        goodMapper.add(good);
    }

    @Override
    public void remove(Integer id) {
        goodMapper.remove(id);
    }
}
